<?php
include_once 'controller/default.php';
include_once 'connection/connection_database.php';

class upload {

    function Insert($upload) {
        $name = explode("/", $upload["upload_url"]);
        $upload_name = end($name);
        $sql = "INSERT INTO upload_file(upload_name, upload_url)"; 
        $sql .= "VALUES('{$upload_name}','{$upload["upload_url"]}')";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }

    function Delete($upload) {
        $sql = "DELETE FROM upload_file WHERE upload_id='{$upload["id"]}'";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }

    function Update($upload) {
        $name = explode("/", $upload["upload_url"]);
        $upload_name = end($name);
        $sql = "UPDATE upload_file SET upload_name={$upload_name}, upload_url='{$upload["upload_url"]}' WHERE upload_id='{$upload["id"]}'";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }

    function FillAll() {
        $sql = "SELECT * FROM upload_file";
        $result = mysql_query($sql) or die(mysql_error());
        return $result;
    }

    function FillOne($upload) {
        $sql = "SELECT * FROM upload_file WHERE upload_id='{$upload["id"]}'";
        $result = mysql_query($sql) or die(mysql_error());
        return mysql_fetch_array($result);
    }
}

?>
